def ispime(p):
    r=2
    while r<=p-1:
        if p%r==0:
            return False
        r+=1
    return True

def has9(q):
    while q!=0:
        if q%10==9:
            return True
        q=int(q/10)
    return False

n=int(input())
m=n+1
while True:
    if ispime(m):
        if has9(m):
            print(m)
            break
        m+=1
    m+=1